**************************************************************************************
** title:		'more europe, less satisfaction with democracy? 					**
** purpose: 	generate tables and figures of manuscript supplementary materials	**
** authors:		ruth dassonneville, alexandra jabbour, michael s. lewis-beck 		**
** date:		july 2020 													    	**
**************************************************************************************	

/*
	The do-file is organized into the following sections: 
	
	1. Main settings 
	
	2. Results in the main text
	
		2.1 Figure 1. Trends in levels of Satisfaction with democracy and satisfaction with the EU (EU 15)
		2.2 Table 1. Explaining satisfaction with democracy
		2.3 Table 2. Explaining individuals’ SWD, EES data (1979-2009)
		2.4 Table 3. Explaining individuals’ SWD, education-based heterogeneity, EES data (1979-2009)
	
	3. Results in the Supplementary materials
	
		3.1 Figure SM1. Trends in levels of Satisfaction with democracy and satisfaction with the EU in ‘new’ EU member states 
		3.2 Table SM1. Explaining satisfaction with democracy in 28 EU countries
		3.3 Table SM2. Explaining satisfaction with democracy and EU legislative work, alternative variables 
		3.4 Table SM3. Explaining satisfaction with democracy, controlling for satisfaction with EU
		3.5 Table SM4. Explaining satisfaction with democracy, lagged effects
		3.6 Table SM5. Explaining satisfaction with democracy, Prais-Winsten models
		3.7 Table SM6. Explaining satisfaction with democracy, Arellano-Bond GMM estimations
		3.8 Table SM7. Explaining satisfaction with democracy, control for European election year
		3.9 Table SM8. Explaining satisfaction with democracy, the conditioning effect of economic crisis
		
*/

* ============================================================================**
* 							1. Main settings
* ============================================================================**


clear all
version 16
set matsize 11000
set maxvar 20000

* Setting file path
	
	cd "~/Dropbox/SWD EU/version final (accepted ES)/replication files"
	
* Define significance stars
	global stars "+ 0.10 * 0.05 ** 0.01 *** 0.001"
	

* ============================================================================**
* 							2. Results in the main text
* ============================================================================**

	* load EB data
	
	use replication_swdeu_macro_def.dta, clear
	
	cd "~/Dropbox/SWD EU/version final (accepted ES)/tables and figures"

		
		* 2.1 Figure 1. Trends in levels of Satisfaction with democracy and satisfaction with the EU (EU 15)
		
	replace country="UK" if country=="United Kingdom" 
	
		foreach i in "Austria" "Belgium" "Denmark" "Finland" "France" "Germany" "Greece" "Ireland" ///
		"Italy" "Luxembourg" "Netherlands" "Portugal" "Spain" "Sweden" "UK" {

		twoway line meanswd year if country=="`i'", legend(off) lpattern(line) clcolor(black) ///
			xline(1986, lcolor(gs9) lwidth(vthin) lp(dot)) ///
			xline(1992, lcolor(gs9) lwidth(vthin) lp(dot)) ///
			xline(1997,  lcolor(gs9) lwidth(vthin) lp(dot)) ///
			xline(2001,  lcolor(gs9) lwidth(vthin) lp(dot)) ///
			xline(2007,  lcolor(gs9) lwidth(vthin) lp(dot))  ///
			yl(1(0.5)4 ,nogrid)  xt("", size(vsmall)) yt("Mean", size(vsmall)) ///
			legend(off) xscale(r(1973(5)2018) noextend) xlabel(1973(5)2018) ///
			xlabel(,labsize(vsmall) angle(65) nogrid) ///
		|| line meanswd_eu year if country=="`i'", clcolor(gs9) lpattern(line) ///
			xline(1986, lcolor(gs9)lwidth(vthin) lp(dot)) ///
			xline(1992, lcolor(gs9)lwidth(vthin) lp(dot)) ///
			xline(1997,  lcolor(gs9)lwidth(vthin) lp(dot)) ///
			xline(2001,  lcolor(gs9)lwidth(vthin) lp(dot)) ///
			xline(2007,  lcolor(gs9)lwidth(vthin) lp(dot)) ///
			yl( 1(0.5)4,nogrid) xt("", size(vsmall)) yt("Mean", size(vsmall)) legend(off) xscale(r(1973(5)2018) noextend) xlabel(1973(5)2018) xlabel(,labsize(vsmall) angle(65) nogrid) ///
			title("`i'")saving(swd_trend_`i'.gph, replace) 
	}

		graph combine swd_trend_Austria.gph swd_trend_Belgium.gph ///
		swd_trend_Denmark.gph swd_trend_Finland.gph swd_trend_France.gph  ///
		swd_trend_Germany.gph swd_trend_Greece.gph swd_trend_Ireland.gph ///
		swd_trend_Italy.gph swd_trend_Luxembourg.gph swd_trend_Netherlands.gph ///
		swd_trend_Portugal.gph swd_trend_Spain.gph swd_trend_Sweden.gph ///
		swd_trend_UK.gph, ///
		col(5) title("") note("Note: Mean SWD Country: Black line, Mean SWD EU: Grey line", size(vsmall)) ///
		saving(combineSWD_EU15.gph, replace)
		
	graph export combineSWD_EU15.png, width(3200)  height(2400)  replace

	replace country="United Kingdom" if country=="UK"
		
		
		
		* 2.2 Table 1. Explaining satisfaction with democracy

	xtset country_num year 
	
	local controls gdplag electionyear  b11.country_num

	eststo m1: xtpcse meanswd L.meanswd totnormslog `controls' if EU15==1,  pairwise
	eststo m2: xtpcse meanswd L.meanswd laborcost_era `controls' if EU15==1,  pairwise
	eststo m3: xtpcse meanswd L.meanswd migration_rate `controls' if EU15==1,  pairwise
	eststo m4: xtpcse meanswd L.meanswd EUsize `controls' if EU15==1,  pairwise
	eststo m5: xtpcse meanswd L.meanswd contribution_negative contribution_positive `controls' if EU15==1,  pairwise
	eststo m6: xtpcse meanswd L.meanswd iodelegationindex `controls' if EU15==1,  pairwise
	eststo m7: xtpcse meanswd L.meanswd eudegree `controls' if EU15==1,  pairwise
	
	esttab m1 m2 m3 m4 m5 m6 m7 using table1.rtf, b(3) se(3) nogap r2 replace	
	
	
	* load ees data

	use replication_swdeu_micro_def.dta, clear 
	
		*2.3 Table 2. Explaining individuals’ SWD, EES data (1979-2009)
	
	eststo m1: mixed swd age female postsecondary totnormslog gdplag   i.country_num || country: || countryyear:
	eststo m2: mixed swd age female postsecondary laborcost_era gdplag    i.country_num || country: || countryyear:
	eststo m3: mixed swd age female postsecondary migration_rate gdplag    i.country_num || country: || countryyear:
	eststo m4: mixed swd age female postsecondary EUsize gdplag    i.country_num || country: || countryyear:
	eststo m5: mixed swd age female postsecondary contribution_negative contribution_positive gdplag    i.country_num || country: || countryyear:
	eststo m6: mixed swd age female postsecondary iodelegationindex gdplag    i.country_num || country: || countryyear:
	eststo m7: mixed swd age female postsecondary eudegree gdplag    i.country_num || country: || countryyear:

	esttab m1 m2 m3 m4 m5 m6 m7 using table2.rtf, b(3) se(3) nogap  replace	
	
		
		*2.4 Table 3. Explaining individuals’ SWD, education-based heterogeneity, EES data (1979-2009)
		
	eststo m1: mixed swd age female i.postsecondary##c.totnormslog gdplag   i.country_num || country: || countryyear: postsecondary
	eststo m2: mixed swd age female i.postsecondary##c.laborcost_era gdplag    i.country_num || country: || countryyear: postsecondary
	eststo m3: mixed swd age female i.postsecondary##c.migration_rate gdplag    i.country_num || country: || countryyear: postsecondary
	eststo m4: mixed swd age female i.postsecondary##c.EUsize gdplag    i.country_num || country: || countryyear: postsecondary
	eststo m5: mixed swd age female i.postsecondary##c.contribution_negative i.postsecondary##c.contribution_positive gdplag    i.country_num || country: || countryyear: postsecondary
	eststo m6: mixed swd age female i.postsecondary##c.iodelegationindex   gdplag    i.country_num || country: || countryyear: postsecondary
	eststo m7: mixed swd age female i.postsecondary##c.eudegree   gdplag    i.country_num || country: || countryyear: postsecondary

	esttab m1 m2 m3 m4 m5 m6 m7 using table3.rtf, b(3) se(3) nogap  replace	

	
		
* ============================================================================**
* 							3. Results in the Supplementary materials
* ============================================================================**
	
	* load data
	
		use replication_swdeu_macro_def, clear 
		
	* Define structure of the data
		
		xtset country_num year 
	
		*3.1 Figure SM1. Trends in levels of Satisfaction with democracy and satisfaction with the EU in ‘new’ EU member states 
		
		foreach i in "Bulgaria" "Croatia" "Cyprus" "CzechRepublic" ///
		"Estonia" "Hungary" "Latvia" "Lithuania" "Malta" "Poland" ///
		"Romania" "Slovakia" "Slovenia" "Spain" {

		twoway line meanswd year if country=="`i'" & year>=2002, legend(off) lpattern(line) clcolor(black) ///
			xline(2007,  lcolor(gs9) lwidth(vthin) lp(dot))  ///
			yl(1(0.5)4 ,nogrid)  xt("", size(vsmall)) yt("Mean", size(vsmall)) ///
			legend(off) xscale(r(2002(2)2018) noextend) xlabel(2002(2)2018) ///
			xlabel(,labsize(vsmall) angle(65) nogrid) ///
		|| line meanswd_eu year if country=="`i'" & year>=2002, clcolor(gs13) lpattern(line) ///
			xline(2007,  lcolor(gs9)lwidth(vthin) lp(dot)) ///
			yl( 1(0.5)4,nogrid) xt("", size(vsmall)) yt("Mean", size(vsmall)) legend(off) xscale(r(2002(2)2018) noextend) xlabel(2002(2)2018) xlabel(,labsize(vsmall) angle(65) nogrid) ///
			title("`i'")saving(swd_trend_`i'.gph, replace) 
	}

		graph combine swd_trend_Bulgaria.gph swd_trend_Croatia.gph ///
		swd_trend_Cyprus.gph swd_trend_CzechRepublic.gph swd_trend_Estonia.gph ///
		 swd_trend_Hungary.gph swd_trend_Latvia.gph swd_trend_Lithuania.gph  ///
		swd_trend_Malta.gph swd_trend_Poland.gph swd_trend_Romania.gph ///
		swd_trend_Slovakia.gph swd_trend_Slovenia.gph, ///
		col(5) title("") note("Note: Mean SWD Country: Black line, Mean SWD EU: Grey line", size(vsmall)) ///
		saving(combineSWD_EU28.gph, replace)
		
	graph export combineSWD_EU28.png, width(3200)  height(2400)  replace
	
	
		* 3.2 Table SM1. Explaining satisfaction with democracy in 28 EU countries
		
	local controls gdplag electionyear  b11.country_num

	eststo m1: xtpcse meanswd L.meanswd totnormslog `controls' ,  pairwise
	eststo m2: xtpcse meanswd L.meanswd laborcost_era `controls' ,  pairwise
	eststo m3: xtpcse meanswd L.meanswd migration_rate `controls'  ,  pairwise
	eststo m4: xtpcse meanswd L.meanswd EUsize `controls' ,  pairwise
	eststo m5: xtpcse meanswd L.meanswd contribution_negative contribution_positive `controls' ,  pairwise
	eststo m6: xtpcse meanswd L.meanswd iodelegationindex `controls' ,  pairwise
	eststo m7: xtpcse meanswd L.meanswd eudegree `controls' ,  pairwise
	
	esttab m1 m2 m3 m4 m5 m6 m7 using tablesm1.rtf, b(3) se(3) nogap r2 replace	

		
		* 3.3 Table SM2. Explaining satisfaction with democracy and EU legislative work, alternative variables 
		
	local controls gdplag electionyear  b11.country_num
	
	eststo m1: xtpcse meanswd L.meanswd regulation `controls' if EU15==1 ,  pairwise
	eststo m2: xtpcse meanswd L.meanswd directive `controls' if EU15==1,  pairwise
	eststo m3: xtpcse meanswd L.meanswd cumtotnorms `controls' if EU15==1,  pairwise
	eststo m4: xtpcse meanswd L.meanswd norms_growth `controls' if EU15==1,  pairwise
	
	esttab m1 m2 m3 m4  using tablesm2.rtf, b(3) se(3) nogap r2 replace

		* 3.4 Table SM3. Explaining satisfaction with democracy, controlling for satisfaction with EU
		
	local controls gdplag electionyear  b11.country_num

	eststo m1: xtpcse meanswd L.meanswd meanswd_eu totnormslog `controls' if EU15==1,  pairwise
	eststo m2: xtpcse meanswd L.meanswd meanswd_eu laborcost_era `controls' if EU15==1,  pairwise
	eststo m3: xtpcse meanswd L.meanswd meanswd_eu migration_rate `controls' if EU15==1,  pairwise
	eststo m4: xtpcse meanswd L.meanswd meanswd_eu EUsize `controls' if EU15==1,  pairwise
	eststo m5: xtpcse meanswd L.meanswd meanswd_eu contribution_negative contribution_positive `controls' if EU15==1,  pairwise
	eststo m6: xtpcse meanswd L.meanswd meanswd_eu iodelegationindex `controls' if EU15==1,  pairwise
	eststo m7: xtpcse meanswd L.meanswd meanswd_eu eudegree `controls' if EU15==1,  pairwise
	
	esttab m1 m2 m3 m4 m5 m6 m7 using tablesm3.rtf, b(3) se(3) nogap r2 replace	

		
		* 3.5 Table SM4. Explaining satisfaction with democracy, lagged effects
		
	sort country_num year 
	by country_num: gen totnormsloglag1 = totnormslog[_n-1]
	by country_num: gen laborcost_eralag1 = laborcost_era[_n-1]
	by country_num: gen migration_ratelag1 = migration_rate[_n-1]
	by country_num: gen contribution_negativelag1 = contribution_negative[_n-1]
	by country_num: gen contribution_positivelag1 = contribution_positive[_n-1]
	by country_num: gen iodelegationindexlag1 = iodelegationindex[_n-1]
	by country_num: gen eudegreelag1 = eudegree[_n-1]
	
	local controls gdplag  electionyear b11.country_num
	
	eststo m1: xtpcse meanswd L.meanswd totnormsloglag1  `controls' if EU15==1,  pairwise
	eststo m2: xtpcse meanswd L.meanswd laborcost_eralag1  `controls' if EU15==1,  pairwise
	eststo m3: xtpcse meanswd L.meanswd migration_ratelag1  `controls' if EU15==1,  pairwise
	eststo m4: xtpcse meanswd L.meanswd contribution_negativelag1 contribution_positivelag1  `controls' if EU15==1,  pairwise
	eststo m5: xtpcse meanswd L.meanswd iodelegationindexlag1  `controls' if EU15==1,  pairwise
	eststo m6: xtpcse meanswd L.meanswd eudegreelag1  `controls' if EU15==1,  pairwise
	
	esttab m1 m2 m3 m4 m5 m6 using tablesm4.rtf, b(3) se(3) nogap r2 replace
	
		
		* 3.6 Table SM5. Explaining satisfaction with democracy, Prais-Winsten models
		
	local controls gdplag electionyear  b11.country_num
	
	eststo m1: xtpcse meanswd totnormslog `controls' if EU15==1,  correlation(ar1) pairwise
	eststo m2: xtpcse meanswd laborcost_era  `controls' if EU15==1,  correlation(ar1) pairwise
	eststo m3: xtpcse meanswd migration_rate  `controls' if EU15==1,  correlation(ar1) pairwise
	eststo m4: xtpcse meanswd EUsize  `controls' if EU15==1,  correlation(ar1) pairwise
	eststo m5: xtpcse meanswd contribution_negative contribution_positive  `controls' if EU15==1,  correlation(ar1) pairwise
	eststo m6: xtpcse meanswd iodelegationindex  `controls' if EU15==1,  correlation(ar1) pairwise
	eststo m7: xtpcse meanswd eudegree  `controls' if EU15==1,  correlation(ar1) pairwise

	esttab m1 m2 m3 m4 m5 m6 m7 using tablasm5.rtf, b(3) se(3) nogap r2  replace
		
		* 3.7 Table SM6. Explaining satisfaction with democracy, Arellano-Bond GMM estimations
	
	local controls gdplag  electionyear 
	
	eststo m1: xtabond meanswd L(0/1).(totnormslog)  `controls', vce(robust)
	estat abond
	xtabond meanswd L(0/1).(totnormslog)  `controls'
	estat sargan
	eststo m2: xtabond meanswd L(0/1).(laborcost_era)  `controls', vce(robust) 
	estat abond
	xtabond meanswd L(0/1).(laborcost_era)  `controls'
	estat sargan
	eststo m3: xtabond meanswd L(0/1).(migration_rate)  `controls', vce(robust) 
	estat abond 
	xtabond meanswd L(0/1).(migration_rate)  `controls'
	estat sargan
	eststo m4: xtabond meanswd L(0/1).(EUsize)  `controls', vce(robust)
	estat abond
	xtabond meanswd L(0/1).(EUsize)  `controls'
	estat sargan
	eststo m5: xtabond meanswd L(0/1).(contribution_negative contribution_positive)  `controls', vce(robust) 
	estat abond
	xtabond meanswd L(0/1).(contribution_negative contribution_positive)  `controls'
	estat sargan
	eststo m6: xtabond meanswd L(0/1).(iodelegationindex)  `controls', vce(robust) 
	estat abond
	xtabond meanswd L(0/1).(iodelegationindex)  `controls'
	estat sargan
	eststo m7: xtabond meanswd L(0/1).(eudegree)  `controls', vce(robust) 
	estat abond
	xtabond meanswd L(0/1).(eudegree)  `controls'
	estat sargan
	
	esttab m1 m2 m3 m4 m5 m6 m7 using tablesm6.rtf, b(3) se(3) nogap r2 replace
	
	
		* 3.8 Table SM7. Explaining satisfaction with democracy, control for European election year
	
	local controls gdplag electionyear epelection b11.country_num

	eststo m1: xtpcse meanswd L.meanswd  totnormslog `controls' if EU15==1,  pairwise
	eststo m2: xtpcse meanswd L.meanswd  laborcost_era `controls' if EU15==1,  pairwise
	eststo m3: xtpcse meanswd L.meanswd  migration_rate `controls' if EU15==1,  pairwise
	eststo m4: xtpcse meanswd L.meanswd  EUsize `controls' if EU15==1,  pairwise
	eststo m5: xtpcse meanswd L.meanswd  contribution_negative contribution_positive `controls' if EU15==1,  pairwise
	eststo m6: xtpcse meanswd L.meanswd  iodelegationindex `controls' if EU15==1,  pairwise
	eststo m7: xtpcse meanswd L.meanswd  eudegree `controls' if EU15==1,  pairwise
	
	esttab m1 m2 m3 m4 m5 m6 m7 using tablesm7.rtf, b(3) se(3) nogap r2 replace	

		
		* 3.9 Table SM8. Explaining satisfaction with democracy, the conditioning effect of economic crisis
	
	eststo m1: xtpcse meanswd L.meanswd i.crisis##c.totnormslog electionyear b11.country_num if EU15==1,  pairwise
	eststo m2: xtpcse meanswd L.meanswd i.crisis##c.laborcost_era electionyear b11.country_num if EU15==1,  pairwise
	eststo m3: xtpcse meanswd L.meanswd i.crisis##c.migration_rate electionyear b11.country_num if EU15==1,  pairwise
	eststo m4: xtpcse meanswd L.meanswd i.crisis##c.EUsize electionyear b11.country_num if EU15==1,  pairwise
	eststo m5: xtpcse meanswd L.meanswd i.crisis##c.contribution_negative i.crisis##c.contribution_positive electionyear b11.country_num if EU15==1,  pairwise
	eststo m6: xtpcse meanswd L.meanswd i.crisis##c.iodelegationindex electionyear b11.country_num if EU15==1,  pairwise
	eststo m7: xtpcse meanswd L.meanswd i.crisis##c.eudegree electionyear b11.country_num if EU15==1,  pairwise

	
	esttab m1 m2 m3 m4 m5 m6 m7 using tablesm8.rtf, b(3) se(3) nogap r2 replace	
	
	
		* 3.10 Table SM9. assessing role of indicators of more `Europe' while keeping N constant
		
	
	gen byte filter= missing(totnormslog, laborcost_era, migration_rate, EUsize, contribution_negative, contribution_positive, iodelegationindex, eudegree)	
	
	local controls gdplag electionyear  b11.country_num
	
	
	eststo m1: xtpcse meanswd L.meanswd totnormslog `controls' if EU15==1 & filter!=1,  pairwise
	eststo m2: xtpcse meanswd L.meanswd laborcost_era `controls' if EU15==1 & filter!=1,  pairwise
	eststo m3: xtpcse meanswd L.meanswd migration_rate `controls' if EU15==1 & filter!=1,  pairwise
	eststo m4: xtpcse meanswd L.meanswd EUsize `controls' if EU15==1 & filter!=1,  pairwise
	eststo m5: xtpcse meanswd L.meanswd contribution_negative contribution_positive `controls' if EU15==1 & filter!=1,  pairwise
	eststo m6: xtpcse meanswd L.meanswd iodelegationindex `controls' if EU15==1 & filter!=1,  pairwise
	eststo m7: xtpcse meanswd L.meanswd eudegree `controls' if EU15==1 & filter!=1,  pairwise
	
	esttab m1 m2 m3 m4 m5 m6 m7 using tablesm9.rtf, b(3) se(3) nogap r2 replace	
	
		
